from service.user_service import UserService

class UserServiceImpl(UserService):
    def __init__(self):
        self.users = {}
        self.next_id = 1

    def get_all_users(self):
        return list(self.users.values())

    def get_user_by_id(self, user_id):
        return self.users.get(user_id)

    def create_user(self, data):
        user = {
            'id': self.next_id,
            'name': data.get('name'),
            'email': data.get('email')
        }
        self.users[self.next_id] = user
        self.next_id += 1
        return user

    def update_user(self, user_id, data):
        if user_id in self.users:
            self.users[user_id].update(data)
            return self.users[user_id]
        return None

    def delete_user(self, user_id):
        return self.users.pop(user_id, None) is not None
